<?php
    session_start();
    include('top.php');
    include('../sql.php');
    $id = $_GET['id'];
    $article = "select * from article where id = $id";
    $article_result = $link->query($article);
    $article_row = mysqli_fetch_array($article_result);
?>
<div class="home-container-body">
    <?php include('nav.php'); ?>
</div>
<script type="text/javascript" src="../edfunction/kindeditor-all-min.js?version=<?php echo time(); ?>"></script>
<script type="text/javascript" src="../edfunction/kindeditor-all.js?version=<?php echo time(); ?>"></script>
<script type="text/javascript" src="../edfunction/kindeditor-min.js?version=<?php echo time(); ?>"></script>
<script type="text/javascript" src="../edfunction/kindeditor.js?version=<?php echo time(); ?>"></script>
<script charset="utf-8" src="../edfunction/lang/zh-CN.js?version=<?php echo time(); ?>"></script>
<script type="text/javascript">
    KindEditor.ready(function (K) {
        window.editor = K.create('#editor_id', {
            width:'800px',
            height:'800px',
            resizeType:0,
        });
    });
    function getContent() {
        html = editor.html();
        editor.sync();
        html = document.getElementById('editor_id').value;
        console.log(html)
    }
</script>
<div class="admin_hone-content">
    <form id="admin_article">
        <table width="100%">
            <tr>
                <td>文章ID</td>
                <td><input type="text" name="id" value="<?php echo $article_row['id']; ?>"></td>
            </tr>
            <tr>
                <td>文章标题</td>
                <td><input type="text" name="title" value="<?php echo $article_row['title']; ?>"></td>
            </tr>
            <tr>
                <td>文章内容</td>
                <td><textarea name="text" rows="20" id="editor_id"><?php echo $article_row['text']; ?></textarea></td>
            </tr>
            <tr>
                <td colspan="2"><input type="submit" value="修改"></td>
            </tr>
        </table>
    </form>
    <div id="ArticleResult"></div>
</div>
<script type="text/javascript" src="../static/js/jquery-3.6.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $('#admin_article').on('submit', function(e){
            e.preventDefault();
            var formData = $(this).serialize();

            $.ajax({
                url: 'control.php?action=updatearticle',
                type: 'POST',
                data: formData,
                success: function(response){
                    $('#ArticleResult').empty();
                    $('#ArticleResult').html(response);
                    location.reload();
                },
                error: function(error){
                    console.log(error);
                    $('#ArticleResult').html('失败，请稍后再试。');
                }
            });
        });
    });
</script>
<?php include('bottom.php'); ?>